package cn.sc.allinpay.allfavour.module.printer;

import com.landicorp.android.eptapi.device.Printer;

import cn.sc.allinpay.allfavour.business.common.data.CheckCouponsRecord;

/**
 * 验券打印
 * author：pany
 * on 2017/11/3 11:48
 */
public class CheckCouponPrinter extends BasePrinter {

    public CheckCouponPrinter(PrintData data) {
        super(data);
    }

    @Override
    protected void printBody(Printer printer, PrintData data) throws Exception {
        printer.setFormat(FormatStyle.createNormalFont());
        printer.println("流 水 号:");
        printer.println(data.getOrderId());
        printer.println("交易时间:" + data.getTime());
        printer.println("交易类型:" + data.getTransName());

        for (int i = 0; i < data.getCheckRecords().size(); i++) {
            CheckCouponsRecord checkRecord = data.getCheckRecords().get(i);
            if (checkRecord.getType() == 0) {
                printer.println("券 名 称:" + checkRecord.getCouponName());
                printer.println("核销金额:" + checkRecord.getUseAmt() + "元");
            } else {
                printer.println("券 名 称:" + checkRecord.getCouponName());
                printer.println("核销数量:x" + checkRecord.getUseNum());
            }
            printer.println("-----------------------------");
        }
        CheckCouponsRecord data0 = data.getCheckRecords().get(0);
        printer.println("备    注:" + (data0 != null ? data0.getDesc() : ""));

        printer.println("");
    }

    @Override
    protected void printFooter(Printer printer, PrintData data) throws Exception {
        printer.feedLine(4);
    }
}
